<?php
require_once "../system.back.php";
require_once '../tools/tools.common.php';
include_once './createcode.php';
if (!array_key_exists("公众号ID",$_SESSION)) {
   echo false ;die;
}

$bm=new C后台管理员();
 if($_REQUEST['businessFlag'] == "ac显示店铺数据"){;
    $stime = $_REQUEST['stime'];
    $etime = $_REQUEST['etime'];
     $公众号ID=$_REQUEST['公众号ID'];
      $返回数据=$bm->f显示公众号的用户汇总($公众号ID,$stime,$etime);
     echo $返回数据;
        die;

} else if($_REQUEST['businessFlag'] == "ac删除用户"){
     $sid = $_REQUEST['sid'];
     $返回数据=$bm->fs删除商户($sid);
     echo $返回数据;
     die;
 }else if($_REQUEST['businessFlag'] == "ac恢复用户"){
     $sid = $_REQUEST['sid'];
     $返回数据=$bm->fh还原商户($sid);
     echo $返回数据;
     die;
 }else if($_REQUEST['businessFlag'] == "ac推广码"){
     $sid = $_REQUEST['sid'];
     $返回数据=$bm->fh生成用户推广二维码($sid);
     echo $返回数据;
     die;
 }else if($_REQUEST['businessFlag'] == "ac查找用户推广详细"){;
    $stime = $_REQUEST['stime'];
    $etime = $_REQUEST['etime'];
    $公众号ID=$_REQUEST['公众号ID'];

    $返回数据=$bm->f显示推广用户($_POST['二维码编号'],$stime,$etime);
    echo $返回数据;
    die;
} else if($_REQUEST['businessFlag'] == "cheng显示文章"){
     $id = $_REQUEST['id'];
     $str = $_REQUEST['str'];
     $返回数据=$bm->fs修改推广文章显示($id,$str);
     echo $返回数据;
     die;
 }else if($_REQUEST['businessFlag'] == "店铺文章审核"){
     $id = $_REQUEST['id'];
     $str = $_REQUEST['str'];
     $店铺id = $_REQUEST['店铺id'];
     $返回数据=$bm->fs审核店铺推广文章($id,$str,$店铺id);
     echo $返回数据;
     die;
 }else if($_REQUEST['businessFlag'] == "ac查找用户"){
     $联系用户 ='';
     $用户信息 = $bm->fc查找用户信息($_POST['name']);
     foreach($用户信息 as $value){
         $联系用户.= "<input type='radio' name='专家id' value='".$value['id']."'>".$value['name']."(".$value['医院'].")&nbsp;";
     }

     echo $联系用户;
 }else if($_REQUEST['businessFlag'] == "成员数"){
     $sql = "select count(*) as 成员  from 群成员 where 群id =".$_REQUEST['id'];
     echo pdo()->selectOne($sql)['成员'];
 }else if($_REQUEST['businessFlag'] == "删除群成员"){
     $用户id = $_REQUEST['用户id'];
     $群id = $_REQUEST['群id'];
     $聊天记录 = pdo()->delete('群聊',array('群id'=>$群id,'用户id'=>$用户id));
     $群成员 = pdo()->delete('群成员',array('群id'=>$群id,'用户id'=>$用户id));
//     $群详情 = pdo()->delete('群详情',array('id'=>$群id,'群主id'=>$用户id));
     echo  $群成员;
 }else if($_REQUEST['businessFlag'] == "删除群聊天"){
     echo  pdo()->delete('群聊',array('id'=>$_REQUEST['聊天记录id']));
 }else if($_REQUEST['businessFlag'] == "咨询信息"){

     $_POST['添加时间']=date("Y-m-d H:i:s",time());

     if($_REQUEST['id']){
         $res=pdo()->update("咨询信息",$_POST,array('id'=>$_REQUEST['id']));
         echo "修改成功";
         return;
     }

     pdo()->insert("咨询信息",$_POST);
     $res=pdo()->lastInsertId();

     echo $res;
     return ;

 }else if($_REQUEST['businessFlag'] == "图文信息"){
     if($_FILES['图片url']['name']){
         $path='../cache/msg_img';
         if(is_dir($path)){
             mkdir($path,"0777");
         }
         $图片url=File_Upload($_FILES['图片url'],$path);
         $_POST["图片url"]=$图片url;
     }
     $_POST['添加时间']=date("Y-m-d H:i:s",time());

     $_POST['咨询id']=$_REQUEST['id'];

     pdo()->insert("咨询详情",$_POST);

     echo "添加成功";
     return ;

 }else if($_REQUEST['businessFlag'] == "查看咨询"){

     $res=pdo()->selectOne("select * from 咨询详情 where id=".$_REQUEST['id']);

    echo json_encode($res);

 }else if($_REQUEST['businessFlag'] == "修改图文信息"){

     if($_FILES['图片']['name']){
         $path='../cache/msg_img';
        if(is_dir($path)){
            mkdir($path,"0777");
        }
         $图片url=File_Upload($_FILES['图片'],$path);
         $_POST["图片url"]=$图片url;
     }
     $res=pdo()->update("咨询详情",array("标题"=>$_POST['标题'],"图片url"=>$_POST['图片url'],"文章url"=>$_POST['文章url'],"description"=>$_POST['description'],"排序"=>$_POST['排序']),array("id"=>$_POST['id']));
    // print_r($_POST);
     echo "修改成功";
 }else if($_REQUEST['businessFlag'] == "推送咨询"){
     if(!$_REQUEST['oid']){
         $修改 = pdo()->update('咨询信息',array('发送'=>'已发送'),array('id'=>$_REQUEST['id']));
     }

     $bm->ff发送咨询信息($_REQUEST['id'],$_REQUEST['oid']);

     return true;
 }
 else if($_REQUEST['businessFlag'] == "推送未成功咨询"){


     $bm->ff发送咨询信息($_REQUEST['id'],'','失败');

     return true;
 } else if($_REQUEST['businessFlag'] == "推送课程"){

     if(!$_REQUEST['oid']){
         $修改 = pdo()->update('语音课程',array('发送'=>'已发送'),array('id'=>$_REQUEST['id']));
     }
     $bm->fc发送图文消息_所有用户('视频课程',$_REQUEST['id'],'Seller17Shipin_Lessons',$_REQUEST['oid']);
     return true;

 }  else if($_REQUEST['businessFlag'] == "课前推送课程"){
     
     $bm->f推送单个课程消息($_REQUEST['id']);
     return true;

 } else if($_REQUEST['businessFlag'] == "推送未成功课程"){

     $bm->fc发送图文消息_所有用户('视频课程',$_REQUEST['id'],'Seller17Shipin_Lessons','','失败');

     return true;
 }

 else if($_REQUEST['businessFlag'] == "删除图文消息"){

     $删除 = pdo()->delete('咨询详情',array('id'=>$_REQUEST['id']));
     return true;
 }

function File_Upload($file,$path){

    $max_file_size=100000000;

    $uptypes=array('image/jpeg','image/png','image/gif','image/jpg');

    if (!is_uploaded_file($file['tmp_name']))

        {
            echo "图片不存在!";
            exit;
        }
        if($max_file_size < $file["size"])
        {
            echo "文件太大!";
            exit;
        }

        if(!in_array($file["type"], $uptypes))

        {
            echo "文件类型不符!".$file["type"];
            exit;
        }

        if(!file_exists($path))
        {
            mkdir($path);
        }

        $filename=$file["tmp_name"];
        $pinfo=pathinfo($file["name"]);
        $ftype=$pinfo['extension'];

        $pathname=time().".".$ftype;

        $destination = $path."/".$pathname;

        $res=move_uploaded_file ($filename, $destination);

        if($res)
        {
            return G_SITE_BASE."/cache/msg_img/".$pathname;
        }

        return "图片上传失败";
}


?>